﻿@page "/fetchemployee"
@inherits EmployeeDataModel

<h1>Employee Data</h1>
<p>This component demonstrates CRUD operation on Employee data</p>

<div class="row">
    <div class="col-md-4">
        <a href='/employee/add' class="btn btn-primary" role="button"><i class="fa fa-user-plus"></i> Add Employee</a>
    </div>
    <div class="input-group col-md-4 offset-md-4">
        <input type="text" class="form-control" placeholder="Search employee by name" @bind="SearchString" @bind:event="oninput"  @onkeyup="FilterEmp"/>
        <div class="input-group-append">
            <button class="btn btn-info" @onclick="FilterEmp">
                <i class="fa fa-search"></i>
            </button>
        </div>
    </div>
</div>
<br />
@if (empList == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <table class='table'>
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Gender</th>
                <th>Department</th>
                <th>City</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var emp in empList)
            {
                <tr>
                    <td>@emp.EmployeeId</td>
                    <td>@emp.Name</td>
                    <td>@emp.Gender</td>
                    <td>@emp.Department</td>
                    <td>@emp.City</td>
                    <td>
                        <a href='/employee/edit/@emp.EmployeeId' class="btn btn-outline-dark" role="button">Edit</a>
                        <button class="btn btn-danger" data-toggle="modal" data-target="#deleteEmpModal" @onclick="(() => DeleteConfirm(emp.EmployeeId))">Delete</button>
                    </td>
                </tr>
            }
        </tbody>
    </table>

    <div class="modal fade" id="deleteEmpModal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h3 class="modal-title">Delete Employee</h3>
                </div>
                <div class="modal-body">
                    <h4>Do you want to delete this employee ??</h4>
                    <table class="table">
                        <tr>
                            <td>Name</td>
                            <td>@emp.Name</td>
                        </tr>
                        <tr>
                            <td>Gender</td>
                            <td>@emp.Gender</td>
                        </tr>
                        <tr>
                            <td>Department</td>
                            <td>@emp.Department</td>
                        </tr>
                        <tr>
                            <td>City</td>
                            <td>@emp.City</td>
                        </tr>
                    </table>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-danger" @onclick="(async () => await DeleteEmployee(emp.EmployeeId))" data-dismiss="modal">YES</button>
                    <button class="btn btn-warning" data-dismiss="modal">No</button>
                </div>
            </div>
        </div>
    </div>
}
